package com.example.administrator.orchardeveryday.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.orchardeveryday.R;
import com.example.administrator.orchardeveryday.bean.FruitBaikeEntity;
import com.example.administrator.orchardeveryday.bean.Main;
import com.example.administrator.orchardeveryday.utils.ImageLoaderHelper;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by Administrator on 15-10-22.
 */
public class FruitBaikeListAdapter extends AppBaseAdapter<Main>{
    DisplayImageOptions displayImage;
    public FruitBaikeListAdapter(List list, Context context) {
        super(list, context);
        DisplayImageOptions displayImage;
    }

    @Override
    public ViewHolder getViewHolder(int position, View convertView, ViewGroup parent) {
        Main main=list.get(position);
        ViewHolder vh = ViewHolder.get(context, convertView, parent, R.layout.item_fruit_baike_listview);
        ImageView iv= (ImageView) vh.findViewById(R.id.fruit_baike_lv_photo_iv);
        TextView title= (TextView) vh.findViewById(R.id.fruit_baike_lv_title_tv);
        TextView summary= (TextView) vh.findViewById(R.id.fruit_baike_lv_summary_tv);
        TextView cTime= (TextView) vh.findViewById(R.id.fruit_baike_lv_ctime_tv);
        TextView worthNum= (TextView) vh.findViewById(R.id.fruit_baike_lv_worth_num_tv);
        TextView commentNum= (TextView) vh.findViewById(R.id.fruit_baike_lv_comment_num_tv);
        ImageLoader.getInstance().displayImage(main.getPhoto(), iv, displayImage);
        title.setText(main.getTitle());
        summary.setText(main.getSummary());
        int time=list.get(position).getStime()-list.get(position).getCtime();
        String commentTime="";
        if(time/60<60)
        {
            commentTime=time/60+"分钟前";
        }
        else
        {
            if(time/60/24<24)
            {
                commentTime=time/60/24+"小时前";
            }
            else
            {
                SimpleDateFormat format=new SimpleDateFormat("yyyy年MM月dd日");
                long x=  System.currentTimeMillis()-time*1000;
                commentTime=format.format(x);
            }
        }
        cTime.setText(commentTime);
        worthNum.setText(main.getWorth_num());
        commentNum.setText(main.getComment_num());
        return vh;
    }
}
